package com.order.web;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.order.dao.CountUnitDBUtil;
import com.order.dao.bean.CountUnit;

public class CountUnitServlet extends HttpServlet{
/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest request,
            HttpServletResponse response)
     throws ServletException,IOException
            {
                doPost(request,response);
             }

public void doPost(HttpServletRequest request,
             HttpServletResponse response)
      throws ServletException,IOException
{
response.setContentType("text/html;charset=gbk");
request.setCharacterEncoding("gbk");
String action=request.getParameter("action");
 CountUnit cu=new CountUnit();

if(action.equals("add")){
	String id=(Integer.parseInt(CountUnitDBUtil.getMaxId())+1)+"";
	String cname=request.getParameter("cname");
	String cbz=request.getParameter("cbz");
	
	if(cname!=null&&cbz!=null){
	 if(cu.insertunit(id,cname,cbz))
	 {
	  RequestDispatcher rd=request.getRequestDispatcher("/countunitManage.jsp");
 	  rd.forward(request,response);
	}
	 }
}
else if(action.equals("del")){
	String id=request.getParameter("id");
	if(id!=null){
    cu.delunit(id);
	RequestDispatcher rd=request.getRequestDispatcher("/countunitManage.jsp");
   	rd.forward(request,response);
	}
	
}
else if(action.equals("update")){
	String id=request.getParameter("id");
	String cname=request.getParameter("cname");
	String cbz=request.getParameter("cbz");
	if(cu.updateunit(id, cname, cbz))
	{
	RequestDispatcher rd=request.getRequestDispatcher("/countunitManage.jsp");
  	rd.forward(request,response);
  	}
}

}
}
